//
//  MSUserCenterCell.m
//  MSJD
//
//  Created by 箭军刘 on 2018/10/28.
//  Copyright © 2018年 xiangbo. All rights reserved.
//

#import "MSUserCenterCell.h"

@interface MSUserCenterCell()

@property (weak, nonatomic) IBOutlet UILabel *tipLabel;
@property (weak, nonatomic) IBOutlet UIImageView *customIcon;
@property (weak, nonatomic) IBOutlet UIImageView *rightIcon;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentLabelRightConstraints;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;


@property (weak, nonatomic) IBOutlet UIView *lineView;

@end

@implementation MSUserCenterCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code

    self.customIcon.layer.cornerRadius = 25.0;
    self.customIcon.clipsToBounds = YES;
}

- (void)refreshUserCenterCellWithTitle:(NSString *)title rightValue:(NSString *)rightValue row:(NSInteger)row {
    self.tipLabel.text = [MSSafeObject stringInfo:title];
    if ([MSSafeObject isNull:rightValue]) {
        self.rightIcon.hidden = NO;
        self.contentLabel.hidden = YES;
    } else {
        self.rightIcon.hidden = YES;
        self.contentLabel.hidden = NO;
        self.contentLabel.text = rightValue;
    }
    self.lineView.hidden = (row == 1 || row == 6 || row == 2 || row == 7)?YES:NO;
}

- (void)refreshSecurityCellWithTitle:(NSString *)title rightValue:(NSString *)rightValue {
    self.tipLabel.text = [MSSafeObject stringInfo:title];
    if ([MSSafeObject isNull:rightValue]) {
        self.rightIcon.hidden = NO;
        self.contentLabel.hidden = YES;
    } else {
        self.rightIcon.hidden = YES;
        self.contentLabel.hidden = NO;
        self.contentLabel.text = [MSSafeObject stringInfo:rightValue];
    }
}

- (void)refreshUserDetailCellWithTitle:(NSString *)title index:(NSInteger)index {
    self.tipLabel.text = [MSSafeObject stringInfo:title];
    MSUser *loginUser = [UserAccesser loadAccount];
    self.contentLabelRightConstraints.constant = 40.0;
    if (index == 0) {
        // 头像
        self.contentLabel.hidden = YES;
        self.customIcon.hidden = NO;
        [self.customIcon setImageWithURL:[NSURL URLWithString:[MSSafeObject stringInfo:loginUser.avatar]] placeholder:[UIImage imageNamed:@"account_default"]];
    } else if (index == 1) {
        // 昵称
        self.contentLabel.hidden = NO;
        self.customIcon.hidden = YES;
        self.contentLabel.text = [MSSafeObject stringInfo:loginUser.username];
    } else if (index == 2) {
        self.contentLabel.hidden = NO;
        self.customIcon.hidden = YES;
        NSString *genderStr = @"未知";
        if ([loginUser.gender integerValue] == 1) {
            genderStr = @"男";
        } else if ([loginUser.gender integerValue] == 2) {
            genderStr = @"女";
        }
        self.contentLabel.text = genderStr;
    }
}

- (void)clearCacheValue {
    self.contentLabel.text = @"0.0M";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
